package com.ruoyi.customer.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.customer.domain.Contract;
import com.ruoyi.customer.domain.InWareHouse;
import com.ruoyi.customer.dto.ContractDTO;
import com.ruoyi.customer.dto.ExportRequestDTO;
import com.ruoyi.customer.dto.InWareHouseDTO;
import com.ruoyi.customer.mapper.ContractMapper;
import com.ruoyi.customer.mapper.InWareHouseMapper;
import com.ruoyi.customer.service.ContractService;
import com.ruoyi.customer.service.InWareHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author:zzm
 * @Date: 2024/9/2 10:43
 */
@Service
public class InWareHouseServiceImpl extends ServiceImpl<InWareHouseMapper, InWareHouse> implements InWareHouseService {

    @Autowired
    private InWareHouseMapper inWareHouseMapper;

    /**
     * 合同信息获取列表
     * @param dto
     * @return
     */
    @Override
    public List<InWareHouse> getList(InWareHouseDTO dto) {
        List<InWareHouse> list = inWareHouseMapper.getList(dto.getCustomerId(),dto.getCustomerNickname(),dto.getEffectiveDate(), dto.getMainItem(),dto.getSubItem());
        return list;
    }

    /**
     * 新增和修改
     * @param ro
     * @return
     */
    @Override
    public Boolean addOrUpdate(InWareHouse ro) {
        if(ro.getId()!=null){
            this.updateById(ro);
        }else{
            this.save(ro);
        }
        return true;
    }

    /**
     * 删除放入回收站
     * @param ids
     */
    @Override
    public void delete(Long[] ids) {
        for (int i = 0; i < ids.length; i++) {
            inWareHouseMapper.deleteByIds(ids[i]);
        }
    }

    /**
     * 导出
     * @param
     */
    @Override
    public void exportByIds(HttpServletResponse response, ExportRequestDTO dto) {
        List<InWareHouse> list = new ArrayList<>();
        if(dto.getIds()==null){
            list = inWareHouseMapper.getList(null,null,null,null,null);
        }else{
            list = inWareHouseMapper.getListByIdS(dto.getIds());
        }
        ExcelUtil<InWareHouse> util = new ExcelUtil<InWareHouse>(InWareHouse.class);
        util.exportExcel(response, list, "库内报价");
        System.out.println("导出数据量：" + list.size());

    }
}
